package org.wll.controller;

import org.wll.entity.Department;
import org.wll.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dept")
public class DeptController {
    
    @Autowired
    DepartmentService deptService;

    //根据id查找dept信息
    @GetMapping("/{did}")
    public Department findDeptById(@PathVariable("did") Integer did) {
        Department dept = deptService.findDeptById(did);
        return dept;
    }

    //查看所有dept信息
    @GetMapping("/all")
    public List<Department> findAllDepts() {
        return deptService.findAllDepts();
    }

    //添加dept信息
    @PostMapping("/add")
    public Department addDept(Department dept) {
        Department dept1 = deptService.addDept(dept);
        return dept1;
    }

    //修改dept信息
    @PutMapping("/update")
    public Department updeEmp(Department dept) {
        Department dept1 = deptService.addDept(dept);
        return dept1;
    }

    //根据id删除dept信息
    @DeleteMapping("/delete/{did}")
    public void deleteDeptById(@PathVariable("did") Integer did) {
        deptService.deleteDeptById(did);
    }
}
